package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.TurnOverMapper;
import com.haoan.index.domain.TurnOver;
import com.haoan.index.service.TurnOverService;

/**
 * 联动图片Service业务层处理
 *
 * @author autoGen
 * @date 2025-01-16
 */
@Service
public class TurnOverServiceImpl extends ServiceImpl<TurnOverMapper,TurnOver> implements TurnOverService
{
    /**
     * 查询联动图片
     *
     * @param id 联动图片主键
     * @return 联动图片
     */
    @Override
    public TurnOver selectTurnOverById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询联动图片列表
     *
     * @param turnOver 联动图片
     * @return 联动图片
     */
    @Override
    public List<TurnOver> selectTurnOverList(TurnOver turnOver)
    {
        LambdaQueryWrapper<TurnOver> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(turnOver.getId() != null, TurnOver::getId, turnOver.getId());
        queryWrapper.like(turnOver.getTitle() != null, TurnOver::getTitle, turnOver.getTitle());
        queryWrapper.eq(turnOver.getBrief() != null, TurnOver::getBrief, turnOver.getBrief());
        queryWrapper.eq(turnOver.getPictureSmall() != null, TurnOver::getPictureSmall, turnOver.getPictureSmall());
        queryWrapper.eq(turnOver.getPictureBig() != null, TurnOver::getPictureBig, turnOver.getPictureBig());
        queryWrapper.eq(turnOver.getOddNumber() != null, TurnOver::getOddNumber, turnOver.getOddNumber());
        queryWrapper.eq(turnOver.getStatus() != null, TurnOver::getStatus, turnOver.getStatus());
        queryWrapper.eq(turnOver.getCreateTime() != null, TurnOver::getCreateTime, turnOver.getCreateTime());
        queryWrapper.eq(turnOver.getCreateBy() != null, TurnOver::getCreateBy, turnOver.getCreateBy());
        queryWrapper.eq(turnOver.getUpdateTime() != null, TurnOver::getUpdateTime, turnOver.getUpdateTime());
        queryWrapper.eq(turnOver.getUpdateBy() != null, TurnOver::getUpdateBy, turnOver.getUpdateBy());
        queryWrapper.eq(TurnOver::getValiFlag,ValiFlag.VALID );
        queryWrapper.orderByAsc(TurnOver::getOddNumber);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增联动图片
     *
     * @param turnOver 联动图片
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTurnOver(TurnOver turnOver)
    {
        return baseMapper.insert(turnOver);
    }

    /**
     * 修改联动图片
     *
     * @param turnOver 联动图片
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTurnOver(TurnOver turnOver)
    {
        return baseMapper.updateById(turnOver);
    }

    /**
     * 批量删除联动图片
     *
     * @param ids 需要删除的联动图片主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTurnOverByIds(Long [] ids)
    {
        TurnOver turnOver = new TurnOver();
        turnOver.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<TurnOver> updQw = new LambdaQueryWrapper<>();
        updQw.in(TurnOver::getId, ids);
        return baseMapper.update(turnOver, updQw);
    }

    /**
     * 删除联动图片信息
     *
     * @param id 联动图片主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        TurnOver turnOver = getById(id);
        turnOver.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(turnOver);
    }
}
